﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Electrical;

namespace YArchitech.Revit.Electric
{
	public class HyRevitUtils
	{
		public static IList<ElementId> GetGroupMemberIds(Group group)
		{
			return null;
		}

		public static Wire CreateWire(Document document, WireType wireType, View view, WiringType wiringType, IList<XYZ> vertexPoints, Connector startConnectorTo, Connector endConnectorTo)
		{
			return Wire.Create(document, wireType.Id, view.Id, wiringType, vertexPoints, startConnectorTo, endConnectorTo);
		}

		public static Wire CreateWire(Document document, WireType wireType, View view, WiringType wiringType, List<XYZ> vertexPoints, Connector startConnectorTo, Connector endConnectorTo)
		{
			Wire result = null;
			if (vertexPoints.Count < 2)
			{
				return result;
			}
			XYZ xyz = vertexPoints[0];
			XYZ xyz2 = vertexPoints[vertexPoints.Count - 1];
			if (startConnectorTo != null)
			{
				XYZ xyz3 = new XYZ(xyz.X, xyz.Y, startConnectorTo.Origin.Z);
				XYZ xyz4 = new XYZ(xyz2.X, xyz2.Y, startConnectorTo.Origin.Z);
				if (xyz3.IsAlmostEqualTo(startConnectorTo.Origin))
				{
					vertexPoints.Remove(xyz);
				}
				if (xyz4.IsAlmostEqualTo(startConnectorTo.Origin))
				{
					vertexPoints.Remove(xyz2);
				}
			}
			if (endConnectorTo != null)
			{
				XYZ xyz5 = new XYZ(xyz.X, xyz.Y, endConnectorTo.Origin.Z);
				XYZ xyz4 = new XYZ(xyz2.X, xyz2.Y, endConnectorTo.Origin.Z);
				if (xyz5.IsAlmostEqualTo(endConnectorTo.Origin))
				{
					vertexPoints.Remove(xyz);
				}
				if (xyz4.IsAlmostEqualTo(endConnectorTo.Origin))
				{
					vertexPoints.Remove(xyz2);
				}
			}
			return Wire.Create(document, wireType.Id, view.Id, wiringType, vertexPoints, startConnectorTo, endConnectorTo);
		}

		public static Wire CreateWire(Document document, WireType wireType, View view, WiringType wiringType, XYZ start, XYZ direction, double size, Connector panelConn, Connector endConnectorTo)
		{
			List<XYZ> list = new List<XYZ>();
			XYZ xyz = new XYZ(start.X, start.Y, panelConn.Origin.Z);
			XYZ item = new XYZ(start.X, start.Y, panelConn.Origin.Z) + direction * size;
			if (!xyz.IsAlmostEqualTo(panelConn.Origin))
			{
				list.Add(xyz);
			}
			list.Add(item);
			return Wire.Create(document, wireType.Id, view.Id, wiringType, list, panelConn, endConnectorTo);
		}
	}
}
